package com.tancire.web.controller.net;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.net.domain.ShopGoodsCategory;
import com.tancire.net.service.IShopGoodsCategoryService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 商品分类Controller
 *
 * @author chenchao
 * @date 2023-11-20
 */
@RestController
@RequestMapping("/net/shopGoodsCategory")
public class ShopGoodsCategoryController extends BaseController {
    @Resource
    private IShopGoodsCategoryService shopGoodsCategoryService;

    /**
     * 查询商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('net:shopGoodsCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopGoodsCategory shopGoodsCategory) {
        startPage();
        List<ShopGoodsCategory> list = shopGoodsCategoryService.selectShopGoodsCategoryList(shopGoodsCategory);
        return getDataTable(list);
    }

    /**
     * 查询全部分类
     *
     * @param shopGoodsCategory
     * @return
     */
    @GetMapping("/listAll")
    public AjaxResult listAll(ShopGoodsCategory shopGoodsCategory) {
        List<ShopGoodsCategory> list = shopGoodsCategoryService.selectShopGoodsCategoryList(shopGoodsCategory);
        return AjaxResult.success("查询商品分类成功", list);
    }

    /**
     * 导出商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('net:shopGoodsCategory:export')")
    @Log(title = "商品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopGoodsCategory shopGoodsCategory) {
        List<ShopGoodsCategory> list = shopGoodsCategoryService.selectShopGoodsCategoryList(shopGoodsCategory);
        ExcelUtil<ShopGoodsCategory> util = new ExcelUtil<ShopGoodsCategory>(ShopGoodsCategory.class);
        util.exportExcel(response, list, "商品分类数据");
    }

    /**
     * 获取商品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('net:shopGoodsCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(shopGoodsCategoryService.selectShopGoodsCategoryById(id));
    }

    /**
     * 新增商品分类
     */
    @PreAuthorize("@ss.hasPermi('net:shopGoodsCategory:add')")
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopGoodsCategory shopGoodsCategory) {
        return toAjax(shopGoodsCategoryService.insertShopGoodsCategory(shopGoodsCategory));
    }

    /**
     * 修改商品分类
     */
    @PreAuthorize("@ss.hasPermi('net:shopGoodsCategory:edit')")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopGoodsCategory shopGoodsCategory) {
        return toAjax(shopGoodsCategoryService.updateShopGoodsCategory(shopGoodsCategory));
    }

    /**
     * 删除商品分类
     */
    @PreAuthorize("@ss.hasPermi('net:shopGoodsCategory:remove')")
    @Log(title = "商品分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(shopGoodsCategoryService.deleteShopGoodsCategoryByIds(ids));
    }
}
